package com.school.controller.common;

import com.wf.captcha.SpecCaptcha;
import com.wf.captcha.base.Captcha;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class CommonController {
    @GetMapping("/common/kaptcha")
    public void defaultKaptcha(HttpServletRequest req, HttpServletResponse resp)throws  Exception {
        resp.setHeader("Cache-Control", "no-store,no-cache");
        resp.setHeader("Pragma", "no-cache");
        resp.setDateHeader("Expires", 0);
        resp.setContentType("image/gif");
        SpecCaptcha captcha = new SpecCaptcha(150, 48, 4);
        captcha.setCharType(Captcha.TYPE_DEFAULT);
        captcha.setFont(Captcha.FONT_1);
        req.getSession().setAttribute("verifyCode", captcha.text().toLowerCase());
        captcha.out(resp.getOutputStream());
    }
}
